﻿/******************************************************************************
 * Name         : Worker.hpp
 * Author       : 671643387
 * Date         : 2015年9月11日
 * Description  :
 *****************************************************************************/

#ifndef PINGPONG_WORKER_HPP_
#define PINGPONG_WORKER_HPP_

#include <boost/shared_ptr.hpp>
#include <boost/unordered_map.hpp>
#include "Client.hpp"

class Worker;
typedef boost::shared_ptr<Worker> WorkerPtr;

class Worker : public dev::base::Thread
{
public:
    Worker(int conns);
    virtual ~Worker(void);

public:
    virtual void stop(void);
    virtual void run(void);

private:
    void onSocketRemovedFromLoop(dev::net::Socket* sock);

private:
    int idGen_;
    int conns_;
    dev::net::EventLoop eventLoop_;

    typedef boost::unordered_map<int, ClientPtr> ClientMap;
    ClientMap clients_;
};

#endif /* PINGPONG_WORKER_HPP_ */
